package org.nstack.header.vm;

import org.nstack.header.core.scheduler.APICreateSchedulerMessage;
import org.nstack.header.core.scheduler.SchedulerVO;
import org.nstack.header.message.APIEvent;
import org.nstack.header.message.APIMessage;
import org.nstack.header.message.APIParam;
import org.nstack.header.message.Message;
import org.nstack.header.rest.RestRequest;
import org.springframework.http.HttpMethod;
import org.nstack.header.identity.Action;
import org.nstack.header.notification.ApiNotification;


@Action(category = VmInstanceConstant.ACTION_CATEGORY)
@RestRequest(
        path = "/vm-instances/{vmUuid}/schedulers/stopping",
        responseClass = APICreateStopVmInstanceSchedulerEvent.class,
        method = HttpMethod.POST,
        parameterName = "params"
)
public class APICreateStopVmInstanceSchedulerMsg extends APICreateSchedulerMessage implements VmInstanceMessage {

    @APIParam(resourceType = VmInstanceVO.class, checkAccount = true, operationTarget = true)
    private String vmUuid;

    public String getVmUuid() {
        return vmUuid;
    }

    public void setVmUuid(String vmUuid) {
        this.vmUuid = vmUuid;
    }

    @Override
    public String getVmInstanceUuid() {
        return getVmUuid();
    }
 
    public static APICreateStopVmInstanceSchedulerMsg __example__() {
        APICreateStopVmInstanceSchedulerMsg msg = new APICreateStopVmInstanceSchedulerMsg();
        msg.setSchedulerName("vm-scheduler");
        msg.setSchedulerDescription("for test stop vm scheduler");
        msg.setStartTime(0L);
        msg.setType("simple");
        msg.setInterval(5);
        msg.setRepeatCount(10);
        msg.setVmUuid(Message.uuid());
        return msg;
    }

    public ApiNotification __notification__() {
        APIMessage that = this;

        return new ApiNotification() {
            @Override
            public void after(APIEvent evt) {
                if (evt.isSuccess()) {
                    ntfy("Created").resource(((APICreateStopVmInstanceSchedulerEvent) evt).getInventory().getUuid(), SchedulerVO.class.getSimpleName())
                            .messageAndEvent(that, evt).done();
                }
            }
        };
    }

}
